# -*- coding:utf-8 -*-
import wx


class FrmWithLogger(wx.Frame):
    """窗口带日志"""
    def __init__(self, parent=None, title="日志窗口", panel: wx.Panel=None):
        wx.Frame.__init__(self,parent, title=title, size=(600,400))

        self.box_all = wx.BoxSizer(wx.VERTICAL)
        self.txt_log = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_WORDWRAP|wx.TE_READONLY|wx.TE_RICH2)
        self.txt_log.SetBackgroundColour(wx.Colour(254,254,254))
        if isinstance(panel, wx.Panel):
            self.panel = panel
            if hasattr(self.panel, 'set_log_ctrl'):
                self.panel.set_log_ctrl(self.txt_log)
            self.box_all.Add(self.panel, flag=wx.EXPAND|wx.ALL,border = 0)
        else:
            self.panel = None
        self.box_all.Add(self.txt_log, proportion=100, flag = wx.EXPAND|wx.ALL,border = 0)
        self.SetSizer(self.box_all)

    def set_panel(self, panel):
        if isinstance(panel, wx.Panel):
            self.panel = panel
            if hasattr(self.panel, 'set_log_ctrl'):
                self.panel.set_log_ctrl(self.txt_log)
            self.box_all.Prepend(self.panel, flag=wx.EXPAND|wx.ALL,border = 0)
        else:
            self.panel = None
        self.Layout()
        pass

if __name__ == "__main__":
    app = wx.App()
    FrmWithLogger().Show()
    app.MainLoop()
